getRemovalPolicyFromStage(
stage):RemovalPolicy
Defined in: src/utils/get-removal-policy-from-stage/get-removal-policy-from-stage.ts:23
Determines the appropriate AWS CDK RemovalPolicy based on the deployment stage.
This function is used to prevent accidental deletion of critical resources (e.g., DynamoDB tables,
Cognito User Pools) in sensitive environments like staging and prod. In these environments,
the policy is set to RETAIN, ensuring resources are preserved even if the stack is deleted.
In other stages (e.g., develop, test), the policy is set to DESTROY to allow cleanup during development.
Parameters
stage
string
The current deployment stage (e.g., "dev", "staging", "prod").
Returns
RemovalPolicy
The appropriate removal policy for the given stage.
Examples
const policy = getRemovalPolicyFromStage(Stage.Prod);
// Returns RemovalPolicy.RETAIN
const policy = getRemovalPolicyFromStage(Stage.Develop);
// Returns RemovalPolicy.DESTROY